<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShopCartTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('shop_cart', ['comment' => '购物车', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('goods_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '商品'])
            ->addColumn('user_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '用户'])
            ->addColumn('goods_sku_price_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '规格'])
            ->addColumn('goods_num', 'integer', ['limit'  =>  10, 'default' => 0, 'comment' => '数量'])
            ->addColumn('snapshot_price', 'decimal', ['precision' => 10, 'scale' => 2, 'null' => true, 'default' => null, 'comment' => '快照价格'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->addIndex('goods_id')
            ->addIndex('user_id')
            ->addIndex('goods_sku_price_id')
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('shop_cart');
        $table->drop();
    }
}
